

$(function() {
    
//    // time picker
//    $('#time-12hr').timepicker({
//        defaultTime: 'current',
//        minuteStep: 1
//    });
//    
//    // time picker
//    $('#time-12hr-sec').timepicker({
//        defaultTime: 'current',
//        showSeconds: true,
//        showMeridian: true,
//        minuteStep: 1,
//        secondStep: 1
//    });
//    
//    // time picker
//    $('#time-24hr').timepicker({
//        defaultTime: 'current',
//        showSeconds: false,
//        showMeridian: false,
//        minuteStep: 1
//    });
//    
//    // time picker
//    $('#time-24hr-sec').timepicker({
//        defaultTime: 'current',
//        showSeconds: true,
//        showMeridian: false,
//        minuteStep: 1,
//        secondStep: 1
//    });
    
//    // date picker
//    $("#date").datepicker({
//        autoclose: true
//    });
//    
//    // datetime picker
//    $("#datetimepicker").datetimepicker();
//    
//    // datetime picker
//    $('#date-time').daterangepicker({
//        singleDatePicker: true,
//        timePicker: true,
//        timePickerIncrement: 1,
//        timePicker12Hour: true,
//        format: 'MM/DD/YYYY hh:mm A'
//    });
//    
//    // daterange picker
//    $("#date-range").daterangepicker({
//    });
//    
//    // date and time range picker
//    $("#date-time-range").daterangepicker({
//        timePicker: true,
//        timePickerIncrement: 1,
//        format: 'MM/DD/YYYY hh:mm A'
//    });
    
//    // hex color picker
//    $('#color-hex').colorpicker();
//    
//    // rgb color picker
//    $('#color-rgb').colorpicker({
//        format: 'rgb'
//    });
//    
//    // rgba color picker
//    $('#color-rgba').colorpicker({
//        format: 'rgba'
//    });
//    
//    // hsl color picker
//    $('#color-hsl').colorpicker({
//        format: 'hsl'
//    });
//    
//    // hsla color picker
//    $('#color-hsla').colorpicker({
//        format: 'hsla'
//    });
    
    // switch
    $('#switch').bootstrapSwitch();
    
    // no-icon spinner
    $('#no-icon-spinner').btSpinner({
        step: 1,
        orientation: 'vertical',
        position: 'right'
    });
    
    // my spinner
    $('#spinner').btSpinner();
    
    // tags input
    $('#tags-input').tagsinput({
        
    });
    
    // chosen
    
    $('#country').chosen();
    $('#country2').chosen();
    $('#country-image').chosen({
        width:"100%",
        html_template: '<img style="border:3px solid black;padding:0px;margin-right:4px" class="{class_name}" src="{url}">'
    });
    
    $('#country-image1').chosen({
        width:"100%"
    });
    
    // wysiwyg
    CKEDITOR.replace(
        'wysiwyg',
        {
            toolbarGroups: [
                {name: 'clipboard'},
                {name: 'editing'},
                {name: 'basicstyles'},
                {name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi']},
                {name: 'styles'},
                {name: 'tools'}
            ]
        }
    );
        
    // form validation
    var rules = {};

//    rules['text']                           = set_rules('text', 'text', 'required|min_length[2]|maxlength[1000]');
//    rules['numeric']                        = set_rules('numeric', 'numeric', 'required|number|min_length[1]|maxlength[11]');
    
    rules['photo']                          = set_rules('photo', 'photo', 'required|valid_extensions[jpg,gif,png]');
    rules['email']                          = set_rules('email', 'email', 'required|valid_email|min_length[1]|max_length[100]');
    rules['spinner']                        = set_rules('spinner', 'spinner', 'required|numeric|min_length[1]|max_length[11]');
    
    rules['color-hex']                      = set_rules('color-hex', 'hex color', 'required|valid_hex_color|min_length[4]|max_length[7]');
    rules['color-rgb']                      = set_rules('color-rgb', 'rgb color', 'required|valid_rgb_color|min_length[10]|max_length[16]');
    rules['color-rgba']                     = set_rules('color-rgba', 'rgba color', 'required|valid_rgba_color|min_length[13]|max_length[23]');
    rules['color-hsl']                      = set_rules('color-hsl', 'hsl color', 'required|valid_hsl_color|min_length[12]|max_length[18]');
    rules['color-hsla']                     = set_rules('color-hsla', 'hsla color', 'required|valid_hsla_color|min_length[15]|max_length[25]');
    
    rules['time-12hr']                      = set_rules('time-12hr', 'time 12 hours', 'required|valid_12hr_time|min_length[7]|max_length[8]');
    rules['time-12hr-sec']                  = set_rules('time-12hr-sec', 'time 12 hours', 'required|valid_12hr_sec_time|min_length[10]|max_length[11]');
    rules['time-24hr']                      = set_rules('time-24hr', 'time 24 hours', 'required|valid_24hr_time|min_length[4]|max_length[5]');
    rules['time-24hr-sec']                  = set_rules('time-24hr-sec', 'time 24 hours', 'required|valid_24hr_sec_time|min_length[7]|max_length[8]');
    
    rules['date']                           = set_rules('date', 'date', 'required|valid_slash_date|min_length[9]|max_length[10]');
    rules['datetimepicker']                 = set_rules('datetimepicker', 'datetimepicker', 'required|valid_slash_datetime');
    rules['date-time']                      = set_rules('date-time', 'date-time', 'required|valid_slash_datetime');
    rules['date-range']                     = set_rules('date-range', 'date-range', 'required|valid_daterange');
    rules['date-time-range']                = set_rules('date-time-range', 'date-time-range', 'required|valid_datetimerange');
    
    rules['tags-input']                     = set_rules('tags-input', 'tags input', 'required|min_length[5]');
    
    rules['button-upload']                  = set_rules('button-upload', 'button upload', 'required|valid_extensions[mp3,wav]');
    rules['file-upload']                    = set_rules('file-upload', 'file upload', 'required|valid_extensions[txt,rtf,doc,docx,csv,xls,xlsx]');
    
    rules['country']                        = set_rules('country', 'country', 'required');
    rules['country2']                       = set_rules('country2', 'country', 'required');
    rules['country-image']                  = set_rules('country-image', 'country image', 'required');
    rules['country-image1']                 = set_rules('country-image1', 'country image', 'required');
    
//    rules['url']                            = set_rules('url', 'url', 'required|valid_url|min_length[1]|max_length[1000]');
//    rules['password']                       = set_rules('password', 'password', 'required|min_length[4]|max_length[1000]');
//    rules['confirm-password']               = set_rules('confirm-password', 'confirm password', 'required|matches[password-validation]|min_length[1]|max_length[1000]');
//    rules['radio-inline-validation']        = set_rules('radio-inline-validation', 'radio', 'required');
//    rules['checkbox-inline-validation']     = set_rules('checkbox-inline-validation', 'checkbox', 'required');
//    rules['dropdown']                       = set_rules('dropdown-validation', 'dropdown', 'required');
//    rules['text-area']                      = set_rules('dropdown-validation', 'dropdown', 'min_length[2]');
    
//    alert( rules['text'].toSource() );
    
    // Validation
    $("#advance-form").validate({
        errorElement: 'small',
        errorClass: 'help-block',
        rules: rules,
        errorPlacement:function(error, element) {
            element.parents('.input-size').append( '<div class="clear-fix"></div>' );
            element.parents('.input-size').append( error);
        },
        highlight: function(label) {
            $(label).closest('.form-group').removeClass('has-error has-success').addClass('has-error');
        },
        success: function(label) {
            label.addClass('valid').closest('.form-group').removeClass('has-error has-success').addClass('has-success');
        }
    });
    
});